package cn.tedu.service;

import cn.tedu.feign.ItemClient;
import cn.tedu.feign.UserClient;
import cn.tedu.pojo.Item;
import cn.tedu.pojo.Order;
import cn.tedu.pojo.User;
import cn.tedu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class orderServiceImpl implements OrderService{
    //注入远程接口
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private UserClient userClient;

    @Override
    public Order getOrder(String orderId) {
        //远程获取order和user
        JsonResult<List<Item>> item = itemClient.getItem(orderId);

        JsonResult<User> user = userClient.getUser(15);

        Order order = new Order()
                .setId(orderId)
                .setUser(user.getData())
                .setItems(item.getData());
        return order;
    }

    @Override
    public void addOrder(Order order) {
        log.info("订单以保存");
    }
}
